package com.woniuxy.cloud.ticket52.movieassembly.apiimpl;


import com.woniuxy.cloud.ticket52.MovieAPI;
import com.woniuxy.cloud.ticket52.common.result.Result;
import com.woniuxy.cloud.ticket52.common.util.ValidationUtils;
import com.woniuxy.cloud.ticket52.form.MovieAddForm;

import com.woniuxy.cloud.ticket52.movieassembly.model.Movie;
import com.woniuxy.cloud.ticket52.movieassembly.service.IMovieService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 电影信息 前端控制器
 * </p>
 *
 * @author rc
 * @since 2021-05-06
 */
@RestController
@Slf4j
public class MovieController implements MovieAPI {

    @Autowired
    private IMovieService movieService;

    @Override
    public Result addMovie(MovieAddForm form) {
        log.info("新增电影：{}",form);
        //校验
        ValidationUtils.validate(form);

        Movie movie = new Movie();
        //按照同名字段拷贝数据
        BeanUtils.copyProperties(form,movie);
        movieService.save(movie);

        return Result.success();
    }

    @Override
    public Result getMovie(int id) {
        log.info("查询电影{}",id);
        Movie byId = movieService.getById(id);
        return Result.success(byId);
    }
}

